const electron = require('electron');
const ipcMain = electron.ipcMain;
const head = 'kuwo/';
const playList = require("../modules/kuwo/playList")
const musicList = require("../modules/kuwo/musicList")
const play = require("../modules/kuwo/playUrl")
const search = require("../modules/kuwo/search")
const singer = require("../modules/kuwo/singer")
const album = require("../modules/kuwo/albumInfo")
const rank = require("../modules/kuwo/rank")
const lrc = require("../modules/kuwo/lrc")
module.exports = class kuwo {

    init() {

        /**
         * 歌单推荐
         */
        ipcMain.handle(head+'list/rank', async (event, args) => {

            return await playList.prototype.index({
                order:'hot',
                rn:30,
                pn:1
            })
        });

        /**
         * 歌单详情
         */
        ipcMain.handle(head+'list/detail', async (event, args) => {
            return await musicList.prototype.getList({
                pid:args.pid,
                pn:1,
                rn:100
            })
        });
        /**
         * 音乐播放链接
         */
        ipcMain.handle(head+'play', async (event, args) => {
            return await play.prototype.getPlayUrl({
                mid:args.mid,
                type:'music'
            })
        });

        /**
         * 搜索
         */
        ipcMain.handle(head+'search', async (event, args) => {
            let type = args.type;
            //console.log(type)
            switch (type){
                case '0':
                case 0:
                    //console.log(11)
                    //console.log(args.keyword)
                    return await search.prototype.searchMusicBykeyWord({
                        key:encodeURI(args.keyword),
                        pn : args.pn,
                        rn : args.rn
                    }) //单曲
                    break;
                case '1':
                case 1 :
                    return await search.prototype.searchAlbumBykeyWord({
                        key:encodeURI(args.keyword),
                        pn : 1,
                        rn : 30
                    }) //专辑
                    break;
                case '2':
                case 2 :
                    return await search.prototype.searchPlayListBykeyWord({
                        key:encodeURI(args.keyword),
                        pn : 1,
                        rn : 30
                    }) //歌单
                    break;
                case '3' :
                case 3 :
                    return await search.prototype.searchArtistBykeyWord({
                        key:encodeURI(args.keyword),
                        pn : 1,
                        rn : 30
                    })//歌手
                    break;
            }


        });

        /**
         * 歌单详情
         */
        ipcMain.handle(head+'singer/songs', async (event, args) => {
            return await singer.prototype.getArtistAlbum({
                artistid:args.id,
                pn:1,
                rn:100
            })
        });

        /**
         * 专辑歌曲
         */
        ipcMain.handle(head+'album', async (event, args) => {
            //console.log(args.id)
            return await album.prototype.getList({
                albumId:args.id,
                pn:1,
                rn:100
            })
        });
        /**
         * 排行榜
         */
        ipcMain.handle(head+'rank', async (event, args) => {

            return await rank.prototype.index()
        });
        /**
         * 排行榜歌单详情
         */
        ipcMain.handle(head+'rank/musicList', async (event, args) => {
            //console.log(args.id)
            return await rank.prototype.getRankMusicList({
                bangId:args.bangId,
                pn:args.pn || 1,
                rn:args.rn || 30
            })
        });
        /**
         * 排行榜歌单详情
         */
        ipcMain.handle(head+'lrc', async (event, args) => {
            return await lrc.prototype.LrcRes(args.musicId)
        });

    }

}
